package com.biao.test_annotation;

import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("com.biao.test_annotation.InitDemo");
        Method[] methods = clazz.getMethods();
        if (methods != null) {
            for (Method method : methods) {
                // 找到使用了 @InitMethod 注解的方法
                boolean hasInitMethod = method.isAnnotationPresent(InitMethod.class);
                if (hasInitMethod) {
                    System.out.println("调用了: " + method.getName() + " 方法");
                    method.invoke(clazz.getConstructor(null).newInstance(null), null);
                }
            }
        }
    }
}
